package com.my.controller;

import com.my.entity.*;
import com.my.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/clazzs")
    public Result queryList(ClazzQueryParam param) throws Exception {
        log.info("班级信息:{},{},{},{},{}",
                param.getName(),param.getBegin(),param.getEnd(),param.getPage(),param.getPageSize());

        // 调用service方法拿到返回的包
        PageBean pageBean = clazzService.queryList(param);

        // 返回pageBean
        return Result.success(pageBean);
    }

    /**
     * 添加班级
     * @param clazz
     * @return
     */
    @PostMapping("/clazzs")
    public Result addClazz(@RequestBody Clazz clazz){
        log.info("controller:{}",clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }

    @GetMapping("/clazzs/{id}")
    public Result getClazzById(@PathVariable Integer id){
        log.info("controller:{}",id);
        Clazz clazz = clazzService.getClazzById(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级信息
     * @param clazz
     * @return
     */
    @PutMapping("/clazzs")
    public Result updateClazz(@RequestBody Clazz clazz){
        log.info("controller:{}",clazz);
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    /**
     * 通过ID删除员工
     * @param id
     * @return
     */
    @DeleteMapping("/clazzs/{id}")
    public Result deleteClazzById(@PathVariable Integer id){
        log.info("controller:{}",id);

        clazzService.deleteClazzById(id);

        return Result.success();
    }

    /**
     * 获取所有的班级
     * @return
     */
    @GetMapping("/clazzs/list")
    public Result getAllClazzList(){
        List<Clazz> clazzList = clazzService.getAllClazzList();

        return Result.success(clazzList);
    }

    /**
     * 班级人数统计
     * @return data
     */
    @GetMapping("/report/studentCountData")
    public Result getStudentCountData(){
        // 收 [无]

        // 发
        ClazzPersonCount clazzPersonCount = clazzService.getStudentCountData();
        log.info("返回的值:{}",clazzPersonCount);
        return Result.success(clazzPersonCount);
    }
}
